1935A - Entertainment in MAC - CodeForces Solution


constructive algorithms strings

Please click on ads to support us..

Python Code:

import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br

sys.setrecursionlimit(100000000)

inp    =lambda: int(input())
strng  =lambda: input().strip() jn     =lambda x,l: x.join(map(str,l)) strl   =lambda: list(input().strip()) mul    =lambda: map(int,input().strip().split()) mulf   =lambda: map(float,input().strip().split()) seq    =lambda: list(map(int,input().strip().split())) 
ceil   =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1

flush  =lambda: stdout.flush()
stdstr =lambda: stdin.readline() stdint =lambda: int(stdin.readline())
stdpr  =lambda x: stdout.write(str(x)) 
mod=1000000007

def decimal_to_binary(decimal_num):
	binary_str = format(int(decimal_num), 'b')
	return binary_str

def print_list(nums):
    s = ' '.join(map(str, nums))
    return s.strip()

def sort_string(word, flag):
        if flag == True:
        sorted_word = ''.join(sorted(word, key=str.lower))
        if flag == False:
        sorted_word = ''.join(sorted(word))
    return sorted_word

def print_single_line(arr):
    print(*arr)
    return

def factors_of_a_number(n):
    result = []
    for i in range(1, math.ceil(n**0.5) + 1):
        if n % i == 0:
            if n // i == i:
                result.append(i)
            else:
                result.append(i)
                result.append(n // i)
        return result

def prime_factors(n):
    result = []
        while n % 2 == 0:
        result.append(2)
        n = n / 2
            for i in range(3,int(math.sqrt(n))+1,2):
                while n % i== 0:
            result.append(i)
            n = n / i
            if n > 2:
        result.append(n)
    return result






if __name__ == "__main__":
    t = inp()
    for _ in range(t):
        n = inp()
        s = input()
        m = len(s)
        flag = True 
        left, right = 0, m - 1
        while left < right:
            if s[left] < s[right]:
                break
            elif s[left] > s[right]:
                flag = False
                break
            else:
                left += 1
                right -= 1
        
        if flag == True:
                        print(s)         else:
            result = s[::-1] + s
            print(result)
            


Comments

Submit
0 Comments
More Questions

221. Maximal Square
1200. Minimum Absolute Difference
1619B - Squares and Cubes
1619A - Square String
1629B - GCD Arrays
1629A - Download More RAM
1629C - Meximum Array
1629D - Peculiar Movie Preferences
1629E - Grid Xor
1629F1 - Game on Sum (Easy Version)
2148. Count Elements With Strictly Smaller and Greater Elements
2149. Rearrange Array Elements by Sign
2150. Find All Lonely Numbers in the Array
2151. Maximum Good People Based on Statements
2144. Minimum Cost of Buying Candies With Discount
Non empty subsets
1630A - And Matching
1630B - Range and Partition
1630C - Paint the Middle
1630D - Flipping Range
1328A - Divisibility Problem
339A - Helpful Maths
4A - Watermelon
476A - Dreamoon and Stairs
1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers